<template>
  <div>
    <el-button @click="ceshi">测试</el-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      socket: null,
    };
  },
  mounted() {
    this.socket = new this.$Ws("ws://localhost:3000");
    this.socket.connect();
  },
  methods: {
    ceshi() {
      console.log(this.socket);
      this.socket
        .send({ type: "message", data: 2222222 })
        .then((res) => {
          console.log("成功");
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
  beforeDestroy() {
    this.socket && this.socket.close();
  },
};
</script>
<style scoped lang="less"></style>
